package com.linln.modules.system.service.impl;

import com.linln.common.utils.HttpServletUtil;
import com.linln.modules.system.domain.Product;
import com.linln.modules.system.repository.ProductRepository;
import com.linln.modules.system.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.domain.*;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author WuKai
 * @date 2021/6/26 11:10
 */
@Service
public class ProductServiceImpl implements ProductService {
    @Autowired
    ProductRepository productRepository;

    @Override
    public Page<Product> findProduct(Product product) {
        Integer pageIndex = HttpServletUtil.getParameterInt("page", 0);
        Integer pageSize = HttpServletUtil.getParameterInt("size", 10);
        Pageable pageRequest = PageRequest.of(pageIndex,pageSize,new Sort(Sort.Direction.DESC,"id"));
//        ExampleMatcher matcher = ExampleMatcher.matching().withMatcher("strorName", ExampleMatcher.GenericPropertyMatchers.startsWith());
        ExampleMatcher matcher = ExampleMatcher.matching();
        Example<Product> example = Example.of(product,matcher);
        Page<Product> page = productRepository.findAll(example,pageRequest);
        return page;
    }
}
